
const express = require('express');
const app = new express();
const path = require('path')
const cookieParser = require('cookie-parser')
const session = require('express-session');



//引入post 数据获取中间件
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded  req.body




app.use(cookieParser()); //它会把cookie 的数据，放 到的 request 对象  的 cookie 属性里去了  
app.use(session({
    secret: 'jingweiyun',
    resave: true,
    saveUninitialized: true,
    cookie: { secure: false, maxAge: 1000 * 10 },
    rolling: true,
    name: 'suibian'
}))

//绑定路由
const userRouter = require('./router/user.js');
const productRouter = require('./router/product.js');



app.use('/user', userRouter); // /user/   /user/edit
app.use('/product', productRouter);

// var greet = express.Router()

// greet.get('/jp', function (req, res) {
//     console.log(req.baseUrl) // /greet
//     res.send('Konichiwa!')
// })

// app.use('/greet', greet) // load the router on '/greet'



app.listen(80, () => {
    console.log(`Example app listening at http://127.0.0.1`)
})